<template>
  <div>
    <div class="mui-card" v-for="(item,i) in goodslist" :key="item.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <mt-switch v-model="$store.getters.getXuanz[item.id]" @change="kaiguan(item.id,$store.getters.getXuanz[item.id])"></mt-switch>
          <img :src="item.thumb_path" alt>
          <div>
            <p class="pls">{{item.title}}</p>
            <div class="cart-s">
              <span class="cart-jg">￥{{item.sell_price}}</span>
              <cartls :goods="$store.getters.getgood[item.id]" :cartid="item.id"></cartls>
              <span @click="remove(item.id,i)">删除</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
            <div class="jies">
            <p>总计</p>
            <p>已勾选商品<span>{{$store.getters.getJiag.count}}</span>件总价￥<span>{{$store.getters.getJiag.amount}}</span></p>
            </div>
            <mt-button type="danger">结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import cartls from "../sub/Cartsl.vue";
export default {
  data() {
    return {
      goodslist: {}
    };
  },
  mounted() {
    this.getGoods();
  },
  methods: {
    getGoods() {
      var idarr = [];
      this.$store.state.car.forEach(item => {
        return idarr.push(item.id);
      });
      if (idarr.length <= 0) {
        return;
      }
      this.$axios
        .get("api/goods/getshopcarlist/" + idarr.join(","))
        .then(res => {
          if (res.data.status === 0) {
            this.goodslist = res.data.message;
          }
        });
    },
    remove(id, index) {
      // 删除购物车中的商品数据
      this.goodslist.splice(index, 1);
      this.$store.commit("removeCart", id);
    },
    kaiguan(id,val){
        console.log(val)
        this.$store.commit("upselected", {id,selected:val});
    }
  },
  components: { cartls }
};
</script>
<style lang="scss" scoped>
.mui-card-content-inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
  img {
    width: 50px;
  }
  .pls {
    color: #333;
  }
  .cart-jg {
    color: red;
  }
  .cart-s {
    display: flex;
  }
}
.jies{
    span{
        color: crimson;
    }
}
</style>
